package com.googlecode.vijayan.dogen;

import java.io.StringWriter;
import java.util.Date;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;

/**
 * 
 * @author Vijayan Srinivasan
 * @since Sep 4, 2013 8:25:44 PM
 * 
 */
public class Main {

	public static void main(String[] args) {
		DataObjectGenerator generator = new DataObjectGenerator();
		generator.setDriver("com.mysql.jdbc.Driver");
		generator.setUrl("jdbc:mysql://localhost:3306/quickorder");
		generator.setUser("root");
		generator.setPassword("mysql");
		try {
			generator.init();
		} catch (MojoExecutionException e) {
			e.printStackTrace();
		}

		VelocityEngine ve = new VelocityEngine();
		ve.setProperty("resource.loader", "classpath");
		ve.setProperty("classpath.resource.loader.class",
				ClasspathResourceLoader.class.getName());

		ve.init();
		VelocityContext context = new VelocityContext();
		context.put("table", generator.getDatabase().getTables().get(0));
		context.put("suffix", "DO");
		context.put("date", new Date());
		context.put("packageName", "com.simple");
		Template daoTemplate = ve.getTemplate("dao.vm");
		Template dtoTemplate = ve.getTemplate("dto.vm");

		StringWriter dto = new StringWriter();
		dtoTemplate.merge(context, dto);
		System.out.println(dto.toString());

		StringWriter dao = new StringWriter();
		daoTemplate.merge(context, dao);
		System.out.println(dao.toString());
	}
}
